﻿using System.Windows.Forms.Design;

namespace UIDesigner
{
    public class UILineDesigner : ControlDesigner
    {
        public override SelectionRules SelectionRules
        {
            get
            {
                UILine control = (UILine)this.Control;
                SelectionRules selectionRules = base.SelectionRules;
                switch (control.LineStyle)
                {
                    case UILine.UILineLineStyle.HorizontallyLine:
                    {
                        SelectionRules[] UnNeedRules = new SelectionRules[] { 
                            SelectionRules.TopSizeable, SelectionRules.BottomSizeable };
                        return FixSelectionRules(selectionRules, UnNeedRules);
                    }
                    case UILine.UILineLineStyle.VerticallyLine:
                    {
                        SelectionRules[] UnNeedRules = new SelectionRules[] {
                            SelectionRules.LeftSizeable, SelectionRules.RightSizeable };
                        return FixSelectionRules(selectionRules, UnNeedRules);
                    }
                }
                return selectionRules;
            }
        }

        public static SelectionRules FixSelectionRules(SelectionRules Rules, SelectionRules[] UnNeed)
        {
            SelectionRules result = Rules;
            if ((UnNeed != null) && (UnNeed.Length > 0))
            {
                foreach (SelectionRules rule in UnNeed)
                {
                    if ((result & rule) == rule)
                    {
                        result -= rule;
                    }
                }
            }
            return result;
        }
    }
}

